package com.zzptc.easyshop.control;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RServlet")
public class RServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter printWriter=response.getWriter();
        printWriter.print("succ=====");


        String uname=request.getParameter("userName");
        String pwd=request.getParameter("passWord");

        Users users = new Users();
        users.setEu_user_name("01");
        users.setEu_password(pwd);
        UserDao ud = new UserDao();
        boolean b = false;
        try {
            UserDao userDao = new UserDao();
            b = userDao.insert(users);
        }catch (Exception e){
            e.printStackTrace();
        }

        if (b){
            request.getRequestDispatcher("succ.jsp").forward(request,response);
        }else {
            request.getRequestDispatcher("error.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
